using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class ProductModelMap : EntityTypeConfiguration<ProductModel>
    {
        public ProductModelMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Description)
                .HasMaxLength(250);

            this.Property(t => t.Author)
                .HasMaxLength(150);

            this.Property(t => t.Catalogue)
                .HasMaxLength(300);

            this.Property(t => t.Note)
                .HasMaxLength(250);

            this.Property(t => t.Name)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("ProductModel");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.CategoryID).HasColumnName("CategoryID");
            this.Property(t => t.ProductTypeID).HasColumnName("ProductTypeID");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.Author).HasColumnName("Author");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Catalogue).HasColumnName("Catalogue");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.Name).HasColumnName("Name");

            // Relationships
            this.HasRequired(t => t.Category)
                .WithMany(t => t.ProductModels)
                .HasForeignKey(d => d.CategoryID);
            this.HasRequired(t => t.ProductType)
                .WithMany(t => t.ProductModels)
                .HasForeignKey(d => d.ProductTypeID);

        }
    }
}
